package org.uim.cricket.analyzer.parsers.match.impl;

import org.uim.cricket.analyzer.parsers.match.MatchIDParsable;
import org.uim.cricket.entities.match.CricketMatch;
import org.uim.cricket.entities.match.MatchID;

/**
 * This class extracts international cricket match ID from a given
 * String. The format is expected to be, 
 * <code>"${match.prefix} ${any.text} ${international.id}"</code>
 * Words will be delimited by one or more consecutive spaces and number
 * of parts must exactly 3.
 * 
 * @author Isuru Madushanka
 *
 */
public class DefaultMatchIDParser implements MatchIDParsable {

	@Override
	public MatchID parseMatchID(String source, CricketMatch match) {
		if (source == null || source.length() == 0) return null;
		
		MatchID id = new MatchID();
		String[] parts = source.split("[ ]+");
		
		if (parts.length == 3) {
			id.setPrefix(parts[0]);
			id.setInternationalID(parts[2]);
		}
		
		return id;
	}

}
